﻿package mortal.game.proxy
{
    import Framework.Util.*;
    import Message.Game.*;
    import Message.Public.*;
    import com.gengine.debug.*;
    import extend.language.*;
    import flash.utils.*;
    import mortal.common.error.*;
    import mortal.game.cache.packCache.*;
    import mortal.game.manager.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.util.*;
    import mortal.game.view.forging.data.*;
    import mortal.game.view.forging.view.*;
    import mortal.mvc.core.*;

    public class EquipProxy extends Proxy
    {
        private var _packRoleCache:PackRolePackCache;
        private var _backPackCache:BackPackCache;
        private var _wardrobeCache:WardrobePackCache;
        private var _refreshing:Boolean = false;
        private var _lastTime:int;
        private var _reqQueue:Array;
        private var _putonUid:String;
        private var _getOffUid:String;
        private var _isAutoTransfer:Boolean;
        private var _isInTime:Boolean;

        public function EquipProxy()
        {
            this._reqQueue = [];
            this._packRoleCache = this.cache.pack.packRolePackCache;
            this._backPackCache = this.cache.pack.backPackCache;
            this._wardrobeCache = this.cache.pack.wardrobePackCache;
            return;
        }// end function

        public function dress(param1:String, param2:String) : void
        {
            var packEquipData:ItemData;
            var roleEquipData:ItemData;
            var packStrengLevel:int;
            var roleStrengLevel:int;
            var highstLevelData:ItemData;
            var putonUid:* = param1;
            var getoffUid:* = param2;
            if (this._isInTime)
            {
                return;
            }
            this._putonUid = putonUid;
            this._getOffUid = getoffUid;
            if (putonUid)
            {
                packEquipData = cache.pack.backPackCache.getItemDataByUid(putonUid);
                if (packEquipData && ItemsUtil.isEquip(packEquipData))
                {
                    if (getoffUid)
                    {
                        roleEquipData = cache.pack.packRolePackCache.getItemDataByUid(getoffUid);
                        if (roleEquipData && roleEquipData.extInfo)
                        {
                            packStrengLevel = packEquipData.extInfo == null ? (0) : (packEquipData.extInfo.strengthen);
                            roleStrengLevel = roleEquipData.extInfo.strengthen;
                            if (packStrengLevel < roleStrengLevel)
                            {
                                if (ForgingConst.IsGuideUseEquip)
                                {
                                    this.equipTransfer(packEquipData.uid, roleEquipData.uid, packEquipData.posType, roleEquipData.posType);
                                    this._isAutoTransfer = true;
                                    ForgingConst.IsGuideUseEquip = false;
                                }
                                else if (!this._isInTime)
                                {
                                    var onCloseHandler1:* = function () : void
            {
                equipTransfer(packEquipData.uid, roleEquipData.uid, packEquipData.posType, roleEquipData.posType);
                _isAutoTransfer = true;
                _isInTime = false;
                return;
            }// end function
            ;
                                    AutoTransferWin.instance.show();
                                    AutoTransferWin.instance.timeOutFunc = onCloseHandler1;
                                    AutoTransferWin.instance.setEquip(packEquipData);
                                    this._isInTime = true;
                                }
                            }
                            else if (EquipmentUtil.isRefreshed(roleEquipData))
                            {
                                this.equipTransfer(roleEquipData.uid, packEquipData.uid, roleEquipData.posType, packEquipData.posType);
                                this._isAutoTransfer = true;
                            }
                        }
                    }
                    else
                    {
                        highstLevelData = cache.pack.backPackCache.getHighstStrengLevelEquip(packEquipData);
                        if (highstLevelData && !this._isInTime)
                        {
                            if (ForgingConst.IsGuideUseEquip)
                            {
                                this.equipTransfer(packEquipData.uid, highstLevelData.uid, packEquipData.posType, highstLevelData.posType);
                                this._isAutoTransfer = true;
                                ForgingConst.IsGuideUseEquip = false;
                            }
                            else
                            {
                                var onCloseHandler2:* = function () : void
            {
                equipTransfer(highstLevelData.uid, packEquipData.uid, highstLevelData.posType, packEquipData.posType);
                _isAutoTransfer = true;
                _isInTime = false;
                return;
            }// end function
            ;
                                AutoTransferWin.instance.show();
                                AutoTransferWin.instance.timeOutFunc = onCloseHandler2;
                                AutoTransferWin.instance.setEquip(packEquipData);
                                this._isInTime = true;
                            }
                        }
                    }
                }
            }
            if (!this._isAutoTransfer && !this._isInTime)
            {
                this.dressEquip(putonUid, getoffUid);
            }
            return;
        }// end function

        private function dressEquip(param1:String, param2:String) : void
        {
            rmi.iRolePrx.dress_async(new AMI_IRole_dress(this.dressSuccess, this.dressFail), param1, param2);
            return;
        }// end function

        private function dressSuccess(param1:AMI_IRole_dress) : void
        {
            Log.debug("装备成功");
            return;
        }// end function

        private function dressFail(param1:Exception) : void
        {
            Log.debug("装备失败");
            var _loc_2:* = param1.message as String;
            MsgManager.showRollTipsMsg(_loc_2, MsgRollTipsType.msgRollTips3);
            return;
        }// end function

        public function strengthen(param1:String, param2:EOperType, param3:Boolean, param4:EPriorityType) : int
        {
            rmi.iEquip.strengthen_async(new AMI_IEquip_strengthen(this.strengthenSuccess, this.strengthenFail, param2), param1, param2, param3, param4);
            return 0;
        }// end function

        private function strengthenSuccess(param1:AMI_IEquip_strengthen, param2:int, param3:SPlayerItem, param4:Array) : void
        {
            var _loc_5:Object = {};
            _loc_5.result = param2;
            _loc_5.resultEquip = param3;
            _loc_5.consumes = param4;
            _loc_5.strengType = (param1.userObject as EOperType).value();
            NetDispatcher.dispatchCmd(ServerCommand.StrengthenInfoUpdate, _loc_5);
            return;
        }// end function

        private function strengthenFail(param1:Exception) : void
        {
            MsgManager.showMouseMsg(ErrorCode.getErrorStringByCode(param1.code), MsgRollTipsType.msgRollTips3);
            NetDispatcher.dispatchCmd(ServerCommand.ForgingStrengthenFail, null);
            return;
        }// end function

        public function jewelEmbed(param1:String, param2:Array) : void
        {
            rmi.iEquip.jewelEmbed_async(new AMI_IEquip_jewelEmbed(this.embedSuccess, this.embedFail), param1, param2);
            return;
        }// end function

        private function embedSuccess(param1:AMI_IEquip_jewelEmbed, param2:int, param3:SPlayerItem, param4:Array) : void
        {
            var _loc_5:Object = {};
            _loc_5.result = param2;
            _loc_5.resultEquip = param3;
            _loc_5.consumes = param4;
            _loc_5.type = 0;
            cache.forging.embedCallBackData = _loc_5;
            MsgManager.showMouseMsg(Language.getString(20543), MsgRollTipsType.msgRollTips2);
            NetDispatcher.dispatchCmd(ServerCommand.EmbedInfoUpdate, _loc_5);
            return;
        }// end function

        private function embedFail(param1:Exception) : void
        {
            MsgManager.showMouseMsg(ErrorCode.getErrorStringByCode(param1.code), MsgRollTipsType.msgRollTips3);
            return;
        }// end function

        public function jewelEmbedNew(param1:String, param2:int, param3:String) : void
        {
            rmi.iEquip.Jewel2Embed_async(new AMI_IEquip_Jewel2Embed(), param1, param2, param3);
            return;
        }// end function

        public function jewelRemove(param1:String, param2:Array) : void
        {
            rmi.iEquip.jewelRemove_async(new AMI_IEquip_jewelRemove(this.removeSuccess), param1, param2);
            return;
        }// end function

        private function removeSuccess(param1:AMI_IEquip_jewelRemove, param2:int, param3:SPlayerItem) : void
        {
            var _loc_4:Object = {};
            _loc_4.result = param2;
            _loc_4.resultEquip = param3;
            _loc_4.type = 1;
            cache.forging.embedCallBackData = _loc_4;
            MsgManager.showMouseMsg(Language.getString(20544), MsgRollTipsType.msgRollTips2);
            NetDispatcher.dispatchCmd(ServerCommand.EmbedInfoUpdate, _loc_4);
            return;
        }// end function

        public function jewelUpdate(param1:String, param2:int, param3:EOperType, param4:Boolean, param5:String) : void
        {
            rmi.iEquip.jewelUpdate_async(new AMI_IEquip_jewelUpdate(this.updateSuccess, this.updateFail), param1, param2, param3, param4, param5);
            return;
        }// end function

        private function updateSuccess(param1:AMI_IEquip_jewelUpdate, param2:int, param3:SPlayerItem, param4:Array) : void
        {
            var _loc_5:Object = {};
            _loc_5.result = param2;
            _loc_5.resultEquip = param3;
            _loc_5.consumes = param4;
            NetDispatcher.dispatchCmd(ServerCommand.GemUpgradeInfoUpdate, _loc_5);
            return;
        }// end function

        private function updateFail(param1:Exception) : void
        {
            MsgManager.showMouseMsg(ErrorCode.getErrorStringByCode(param1.code), MsgRollTipsType.msgRollTips3);
            return;
        }// end function

        public function jewelUpdateNew(param1:String, param2:int, param3:int, param4:Boolean) : void
        {
            rmi.iEquip.Jewel2Update_async(new AMI_IEquip_Jewel2Update(), param1, param2, param3, param4);
            return;
        }// end function

        public function jewelUpdate3(param1:String, param2:int, param3:Dictionary, param4:Boolean) : void
        {
            rmi.iEquip.Jewel3Update_async(new AMI_IEquip_Jewel3Update(), param1, param2, param3, param4);
            return;
        }// end function

        public function JewelAdvance(param1:String, param2:int, param3:Dictionary, param4:Boolean = false) : void
        {
            rmi.iEquip.JewelAdvance_async(new AMI_IEquip_JewelAdvance(), param1, param2, param3, param4);
            return;
        }// end function

        public function equipRefresh(param1:String, param2:EOperType, param3:Boolean, param4:Boolean, param5:EPriorityType, param6:Dictionary, param7:Dictionary, param8:int) : void
        {
            var _loc_9:* = getTimer();
            if (_loc_9 - this._lastTime > 500)
            {
                this._lastTime = _loc_9;
                this._refreshing = false;
            }
            else
            {
                this._refreshing = true;
            }
            if (!this._refreshing)
            {
                this._refreshing = true;
                rmi.iEquip.equipRefresh_async(new AMI_IEquip_equipRefresh(this.onRefreshSuccess, this.refreshFail), param1, param2, param3, param4, param5, param6, param7, param8);
            }
            return;
        }// end function

        private function onRefreshSuccess(param1:AMI_IEquip_equipRefresh, param2:int, param3:SPlayerItem, param4:Array) : void
        {
            MsgManager.showMouseMsg(Language.getString(20545), MsgRollTipsType.msgRollTips2);
            var _loc_5:Object = {};
            _loc_5.result = param2;
            _loc_5.resultEquip = param3;
            _loc_5.consumes = param4;
            _loc_5.type = ForgingConst.OperType_Refresh;
            NetDispatcher.dispatchCmd(ServerCommand.RefreshInfoUpdate, _loc_5);
            return;
        }// end function

        private function refreshFail(param1:Exception) : void
        {
            MsgManager.showMouseMsg(ErrorCode.getErrorStringByCode(param1.code), MsgRollTipsType.msgRollTips3);
            return;
        }// end function

        public function equipRefreshReplace(param1:String, param2:int) : void
        {
            rmi.iEquip.equipRefreshReplace_async(new AMI_IEquip_equipRefreshReplace(this.replaceSuccess), param1, param2);
            return;
        }// end function

        private function replaceSuccess(param1:AMI_IEquip_equipRefreshReplace, param2:int, param3:SPlayerItem) : void
        {
            MsgManager.showMouseMsg(Language.getString(20546), MsgRollTipsType.msgRollTips2);
            var _loc_4:Object = {};
            _loc_4.result = param2;
            _loc_4.resultEquip = param3;
            _loc_4.type = ForgingConst.OperType_Replace;
            NetDispatcher.dispatchCmd(ServerCommand.RefreshInfoUpdate, _loc_4);
            return;
        }// end function

        public function equipColorAdvance(param1:String, param2:EOperType, param3:Boolean, param4:EPriorityType) : void
        {
            rmi.iEquip.equipColorAdvance_async(new AMI_IEquip_equipColorAdvance(this.colorAdvanceSuccess, this.colorAdvanceFail), param1, param2, param3, param4);
            return;
        }// end function

        private function colorAdvanceSuccess(param1:AMI_IEquip_equipColorAdvance, param2:int, param3:SPlayerItem, param4:Array) : void
        {
            MsgManager.showMouseMsg(Language.getString(20547), MsgRollTipsType.msgRollTips2);
            var _loc_5:Object = {};
            _loc_5.result = param2;
            _loc_5.resultEquip = param3;
            _loc_5.cosumes = param4;
            NetDispatcher.dispatchCmd(ServerCommand.EquipColorInfoUpdate, _loc_5);
            return;
        }// end function

        private function colorAdvanceFail(param1:Exception) : void
        {
            MsgManager.showMouseMsg(ErrorCode.getErrorStringByCode(param1.code), MsgRollTipsType.msgRollTips3);
            return;
        }// end function

        public function equipQualityAdvance(param1:String, param2:EOperType, param3:Boolean, param4:EPriorityType) : void
        {
            rmi.iEquip.equipQualityAdvance_async(new AMI_IEquip_equipQualityAdvance(this.qualityAdvanceSuccess), param1, param2, param3, param4);
            return;
        }// end function

        private function qualityAdvanceSuccess(param1:AMI_IEquip_equipQualityAdvance, param2:int, param3:SPlayerItem, param4:Array) : void
        {
            MsgManager.showMouseMsg(Language.getString(21248), MsgRollTipsType.msgRollTips2);
            var _loc_5:Object = {};
            _loc_5.result = param2;
            _loc_5.resultEquip = param3;
            _loc_5.cosumes = param4;
            NetDispatcher.dispatchCmd(ServerCommand.EquipQualInfoUpdate, _loc_5);
            return;
        }// end function

        public function equipTransfer(param1:String, param2:String, param3:int, param4:int) : void
        {
            rmi.iEquip.equipTransfer_async(new AMI_IEquip_equipTransfer(this.transferSuccess, this.transferFail), param1, param3, param2, param4);
            return;
        }// end function

        private function transferSuccess(param1:AMI_IEquip_equipTransfer) : void
        {
            NetDispatcher.dispatchCmd(ServerCommand.EquipTransferInfoUpdate, {});
            if (this._isAutoTransfer)
            {
                this._isAutoTransfer = false;
                this.dressEquip(this._putonUid, this._getOffUid);
            }
            return;
        }// end function

        private function transferFail(param1:Exception) : void
        {
            MsgManager.showMouseMsg(ErrorCode.getErrorStringByCode(param1.code), MsgRollTipsType.msgRollTips3);
            return;
        }// end function

        public function itemDecompose(param1:Array) : void
        {
            rmi.iEquip.itemDecompose_async(new AMI_IEquip_itemDecompose(this.onDecomposeSucc), param1);
            return;
        }// end function

        private function onDecomposeSucc(param1:AMI_IEquip_itemDecompose) : void
        {
            NetDispatcher.dispatchCmd(ServerCommand.ForgingDecomposeSucc, null);
            return;
        }// end function

        public function decomposeBagMoveToBag(param1:Array, param2:int) : void
        {
            rmi.iEquip.decomposeBagMoveToBag_async(new AMI_IEquip_decomposeBagMoveToBag(this.onMoveSucc, this.onMoveFail, param2), param1);
            return;
        }// end function

        private function onMoveSucc(param1:AMI_IEquip_decomposeBagMoveToBag) : void
        {
            var _loc_2:* = param1.userObject as int;
            NetDispatcher.dispatchCmd(ServerCommand.ForgingDecomposePickSucc, _loc_2);
            return;
        }// end function

        private function onMoveFail(param1:Exception) : void
        {
            MsgManager.showMouseMsg(ErrorCode.getErrorStringByCode(param1.code), MsgRollTipsType.msgRollTips3);
            return;
        }// end function

    }
}
